<template>
  <div id="app">
    <el-table
      :data="tableData"
      border
      style="width: 100%"
      stripe
      :header-cell-style="{ background: '#f7f7f7', color: '#1f6aa1' }"
    >
      <el-table-column type="index" />
      <el-table-column prop="Id" label="Id" />

      <el-table-column prop="Date" label="日期" />
      <el-table-column prop="Name" label="名称" />
      <el-table-column label="状态">
        <template #default="scope">
          <el-tag type="success" v-if="scope.row.status == 0">白名单</el-tag>
          <el-tag type="danger" v-if="scope.row.status == 1">黑名单</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template #default="scope">
          <el-button
            type="danger"
            size="small"
            @click="deleteCard(scope.$index, scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      class="pagination"
      background
      layout="prev, pager, next"
      :total="tableData.length"
      :page-size="pageSize"
    >
    </el-pagination>
  </div>
</template>

<script>
import { toRefs, reactive, onMounted } from "vue";
import requst from "../../http/request";
import { ElMessage } from "element-plus";
export default {
  setup() {
    const list = reactive({
      tableData: [],
      pageSize: 5,
    });
    const userInfo = JSON.parse(sessionStorage.getItem("userInfo"));
    const getlist = async () => {
      const { data } = await requst.user_view({
        count: list.pageSize,
        user_id: userInfo.user_id,
      });
      list.tableData = data.data;
    };
    onMounted(getlist);
    const deleteCard = async (index, row) => {
      const { data } = await requst.kdcDelete({
        Id: row.Id,
        user_id: userInfo.user_id,
      });
       ElMessage({
          message: data.message,
          type: "success"
        });
        getlist();
    };
    return {
      ...toRefs(list),
      deleteCard,
    };
  },
};
</script>

<style scoped>
#app {
  background: #f8f8f8;
  width: 100%;
  padding: 10px;
}
.pagination {
  justify-content: center;
  margin: 20px 0;
}
</style>